package com.jack006.article;

import com.jack006.api.config.RabbitMQDelayConfig;
import com.jack006.article.service.ArticleService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Classname RabbitMQConsumer
 * @Description
 * @Date 2021-07-28 22:06
 * @Created by jack
 */
@Component
public class RabbitMQDelayConsumer {


    @Autowired
    private ArticleService articleService;

    @RabbitListener(queues = {RabbitMQDelayConfig.QUEUE_DELAY})
    public void watchQueue(String payload, Message message) {

        System.out.println("delay.payload-->"+payload);
        String routingKey = message.getMessageProperties().getReceivedRoutingKey();
        System.out.println("delay.routingKey-->"+routingKey);
        System.out.println("消费者消费的时间"+new Date());

        // 消费者接收到定时发布的延时,修改文章的状态为即时发布
        String articleId = payload;
        articleService.updateArticleToPublish(articleId);
    }
}
